#include "comm.h"
#include "shell_port.h"




// 预期的指令数据
const uint8_t led1_cmd[] = {0x55, 0xAA, 0x55, 0xAA, 0xFF, 0x0F, 0xA1, 0x00, 0x00, 0x18, 0x49, 0x16, 0xE9, 0x16, 0xE9};
const uint8_t led2_cmd[] = {0x55, 0xAA, 0x55, 0xAA, 0xFF, 0x0F, 0xA4, 0xB1, 0x00, 0x7C, 0x18, 0x16, 0xE9, 0x16, 0xE9};
const uint8_t led3_cmd[] = {0x55, 0xAA, 0x55, 0xAA, 0xFF, 0x0F, 0xA6, 0x00, 0x00, 0xA9, 0x88, 0x16, 0xE9, 0x16, 0xE9};



void Comm_init(void)
{
  // 启动串口接收中断
//  HAL_UART_Receive_IT(&huart4, &Ser4_RX_Buf[0], 1);
	HAL_UART_IRQHandler(&huart4); // 调用HAL库的UART中断处理函数
	HAL_TIM_Base_Start_IT(&htim2);
}


void Comm_loop(void)
{
	  if (Ser4_RX_Flag)
    {
      // 检查接收到的指令
      if (memcmp(Ser4_RX_Buf, led1_cmd, sizeof(led1_cmd)) == 0)
      {
//        process_command(CMD_LED1);
      }
      else if (memcmp(Ser4_RX_Buf, led2_cmd, sizeof(led2_cmd)) == 0)
      {
//        process_command(CMD_LED2);
      }
      else if (memcmp(Ser4_RX_Buf, led3_cmd, sizeof(led3_cmd)) == 0)
      {
//        process_command(CMD_LED3);
      }
      
      // 重置接收状态
      Ser4_RX_Flag = 0;
      Ser4_DA_Long = 0;
      
      // 重新启动接收中断
      HAL_UART_Receive_IT(&huart4, &Ser4_RX_Buf[0], 1);
    }
}
